import java.util.PriorityQueue;
import java.util.concurrent.PriorityBlockingQueue;

class myThread extends Thread{//自己定义类,继承Thread类,重写run方法
    @Override
    public void run(){
        boolean i=true;
        while (i){
            System.out.println("hello t");
            /*try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }*/
            i=false;
        }

    }
}
class myRunnable implements Runnable{//使用自定义类,实现Runnable接口,来创建新的线程
    @Override
    public void run(){
        System.out.println("hello t1");
        /*try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }*/
    }
}
public class Main {
    public static void main(String[] args) {
        //使用定义的类来实现Thread
        Thread t=new myThread();

        //使用自定义类,实现Runnable接口,来创建线程
        myRunnable runnable=new myRunnable();
        Thread t1=new Thread(runnable);

        ///////////////////使用lambda表达式来实现Thread类
        Thread t2=new Thread(()->{
            try {//线程等待
                t.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            try {//线程等待
                t1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("hello t2");
            /*try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }*/
        });

        //////////////////使用匿名内部类来实现Thread类
        Thread t3=new Thread(){
            @Override
            public void run(){
                try {//线程等待
                    t2.join();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("hello t3");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        };
        //////////////创建线程,并且对其命名
        Thread t4=new Thread(()->{
            try {//线程等待
                t3.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("hello t4");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },"我的线程");


        t.start();//创建新线程
        t1.start();
        t2.start();
        t3.start();
        t4.start();

        try {//线程等待
            t4.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        //////////////////等待3秒再执行main线程
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("hello main");

       /* while (true){//执行main线程
            System.out.println("hello main");
        }*/
        System.out.println(t4.getState());
        //PriorityBlockingQueue

    }

}